package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RecordBorcart;
import com.ruoyi.system.service.IRecordBorcartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 借阅车Controller
 *
 * @author admin
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/system/borcart")
public class RecordBorcartController extends BaseController {
    @Autowired
    private IRecordBorcartService recordBorcartService;

    /**
     * 查询借阅车列表
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordBorcart recordBorcart) {
        startPage();
        List<RecordBorcart> list = recordBorcartService.selectRecordBorcartList(recordBorcart);
        return getDataTable(list);
    }

    /**
     * 导出借阅车列表
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:export')")
    @Log(title = "借阅车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordBorcart recordBorcart) {
        List<RecordBorcart> list = recordBorcartService.selectRecordBorcartList(recordBorcart);
        ExcelUtil<RecordBorcart> util = new ExcelUtil<RecordBorcart>(RecordBorcart.class);
        util.exportExcel(response, list, "借阅车数据");
    }

    /**
     * 获取借阅车详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:query')")
    @GetMapping(value = "/{cartId}")
    public AjaxResult getInfo(@PathVariable("cartId") Long cartId) {
        return AjaxResult.success(recordBorcartService.selectRecordBorcartByCartId(cartId));
    }

    /**
     * 新增借阅车
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:add')")
    @Log(title = "借阅车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordBorcart recordBorcart) {
        return toAjax(recordBorcartService.insertRecordBorcart(recordBorcart));
    }

    /**
     * 修改借阅车
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:edit')")
    @Log(title = "借阅车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordBorcart recordBorcart) {
        return toAjax(recordBorcartService.updateRecordBorcart(recordBorcart));
    }

    /**
     * 删除借阅车
     */
    @PreAuthorize("@ss.hasPermi('system:borcart:remove')")
    @Log(title = "借阅车", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cartIds}")
    public AjaxResult remove(@PathVariable Long[] cartIds) {
        return toAjax(recordBorcartService.deleteRecordBorcartByCartIds(cartIds));
    }
}
